<extend name="common:base" />
<block name="content">
    <div class="banx-a" style="margin-top:0;">
        <div class="a-1">
            <div class="cz-img">
                <notempty name="avatar['avatar']">
                    <img name="head" src="{$avatar['avatar']}"/>
                    <else/>
                    <img class="photo" name="head" src="./Public/images/default.png"/>
                </notempty>
            </div>
            <div class="cz-name">
                <p><a>{:session('auser_name')}</a></p>
                <p><a>{:session('amobile')}</a></p>
            </div>
        </div>
        <div class="a-2">
            <div class="a-2b">
                <div class="qian">
                    <p>充值金额</p>
                    <select id="amt">
                        <option value="">选择金额</option>
                        <option value="100">100</option>
                        <option value="200">200</option>
                        <option value="500">500</option>
                        <option value="1000">1000</option>
                        <option value="2000">2000</option>
                        <option value="3000">3000</option>
                        <option value="10000">10000</option>
                    </select>
                </div>
            </div>
            <div class="a-2b other_amt">
                <div class="qian">
                    <p>其他金额</p>
                    <input type="text" id="other_amt" placeholder="其他：100以上整数金额" />
                </div>
            </div>
            <div class="a-2c">
                <div class="qian">
                    <p>支付方式</p>
                    <select id="pay_type">
                        <option value="">请选择</option>
                        <foreach name="payments" item="pay">
                            <option value="{$pay.p_id}">{$pay.p_name}</option>
                        </foreach>
                    </select>
                </div>
            </div>
        </div>
        <span class="tj" id="save">去支付</span>
    </div>
    <div id="jump_pay"></div>
</block>
<block name="CSS">
    <link rel="stylesheet" href="{:C('__STATIC__')}{$theme}/Static/{:C('css')}/congzhi.css" />
</block>
<block name="JS">
    <script type="text/javascript">
        $(function () {
            $('#save').click(function () {
                var amt_o = $('#amt').val();
                var other_amt = $('#other_amt').val();
                var pay_type = $("#pay_type").val();
                var reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
                if (!reg.test(amt_o) && !reg.test(other_amt)) {
                    layer.msg('金额不正确', {time: 1500});
                    return false;
                }
                if (!pay_type) {
                    layer.msg('请选择支付方式', {time: 1500});
                    return false;
                }
                var amt = 0;
                if(other_amt){
                    amt = other_amt;
                }else{
                    amt = amt_o;
                }
                $.ajax({
                    url:"{:U('Payment/recharge')}",
                    type:"post",
                    data:{amt:amt,pay_type: pay_type},
                    success: function (data)
                    {
                        if (data.status == "success") {
                            $("#jump_pay").html(data.msg);
                            layer.msg("支付跳转中..." ,{time: 3000});
                        } else {
                            layer.msg(data.msg, {time:1500});
                        }
                    }
                });
            })
        });
    </script>
</block>
